﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class frmMaHoaSanPham
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnNew As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnDelete1 As System.Windows.Forms.Button
    Friend WithEvents txtMaHangHoa As System.Windows.Forms.TextBox
    Friend WithEvents BtnClose As System.Windows.Forms.Button
    Friend WithEvents BtnIn As System.Windows.Forms.Button
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents CboDangBaoChe As MTGCComboBox
    Friend WithEvents GhichuDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MatinhDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents CboSanPham As MTGCComboBox
    Friend WithEvents TxtTenSanPham As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents CboDangDongGoi As MTGCComboBox
    Friend WithEvents TxtDangDongGoi As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents TblmahoathanhphamBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataSetForm_Sop As PHUQUI.DataSetForm_Sop
    Friend WithEvents TxtKyHieu As System.Windows.Forms.TextBox
    Friend WithEvents txtCapNhatThanh As System.Windows.Forms.TextBox
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents MaduocphamDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MabaocheDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TenduocphamDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MadonggoiDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TxtTenDangBaoChe As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmMaHoaSanPham))
        Dim DataGridViewCellStyle1 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Me.btnSave = New System.Windows.Forms.Button
        Me.txtMaHangHoa = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnNew = New System.Windows.Forms.Button
        Me.btnDelete1 = New System.Windows.Forms.Button
        Me.BtnClose = New System.Windows.Forms.Button
        Me.BtnIn = New System.Windows.Forms.Button
        Me.Label5 = New System.Windows.Forms.Label
        Me.TxtTenDangBaoChe = New System.Windows.Forms.TextBox
        Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.MaduocphamDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.MabaocheDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TenduocphamDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.MadonggoiDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TblmahoathanhphamBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataSetForm_Sop = New PHUQUI.DataSetForm_Sop
        Me.CboDangBaoChe = New MTGCComboBox
        Me.CboSanPham = New MTGCComboBox
        Me.TxtTenSanPham = New System.Windows.Forms.TextBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.CboDangDongGoi = New MTGCComboBox
        Me.TxtDangDongGoi = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.TxtKyHieu = New System.Windows.Forms.TextBox
        Me.txtCapNhatThanh = New System.Windows.Forms.TextBox
        Me.Label7 = New System.Windows.Forms.Label
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TblmahoathanhphamBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetForm_Sop, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSave
        '
        Me.btnSave.BackColor = System.Drawing.Color.Transparent
        Me.btnSave.Image = CType(resources.GetObject("btnSave.Image"), System.Drawing.Image)
        Me.btnSave.Location = New System.Drawing.Point(252, 150)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(96, 24)
        Me.btnSave.TabIndex = 5
        Me.btnSave.UseVisualStyleBackColor = False
        '
        'txtMaHangHoa
        '
        Me.txtMaHangHoa.BackColor = System.Drawing.SystemColors.Info
        Me.txtMaHangHoa.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtMaHangHoa.ForeColor = System.Drawing.Color.Red
        Me.txtMaHangHoa.Location = New System.Drawing.Point(291, 40)
        Me.txtMaHangHoa.MaxLength = 10
        Me.txtMaHangHoa.Name = "txtMaHangHoa"
        Me.txtMaHangHoa.Size = New System.Drawing.Size(138, 26)
        Me.txtMaHangHoa.TabIndex = 1
        Me.txtMaHangHoa.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(52, 44)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 18)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "Ký hiệu Danh Mục"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(196, 3)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(380, 24)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "MÃ HÓA DANH MỤC SẢN PHẨM"
        '
        'btnNew
        '
        Me.btnNew.Image = CType(resources.GetObject("btnNew.Image"), System.Drawing.Image)
        Me.btnNew.Location = New System.Drawing.Point(147, 150)
        Me.btnNew.Name = "btnNew"
        Me.btnNew.Size = New System.Drawing.Size(96, 24)
        Me.btnNew.TabIndex = 6
        '
        'btnDelete1
        '
        Me.btnDelete1.Image = CType(resources.GetObject("btnDelete1.Image"), System.Drawing.Image)
        Me.btnDelete1.Location = New System.Drawing.Point(357, 150)
        Me.btnDelete1.Name = "btnDelete1"
        Me.btnDelete1.Size = New System.Drawing.Size(96, 24)
        Me.btnDelete1.TabIndex = 29
        '
        'BtnClose
        '
        Me.BtnClose.Image = CType(resources.GetObject("BtnClose.Image"), System.Drawing.Image)
        Me.BtnClose.Location = New System.Drawing.Point(572, 150)
        Me.BtnClose.Name = "BtnClose"
        Me.BtnClose.Size = New System.Drawing.Size(96, 24)
        Me.BtnClose.TabIndex = 30
        '
        'BtnIn
        '
        Me.BtnIn.Image = CType(resources.GetObject("BtnIn.Image"), System.Drawing.Image)
        Me.BtnIn.Location = New System.Drawing.Point(464, 150)
        Me.BtnIn.Name = "BtnIn"
        Me.BtnIn.Size = New System.Drawing.Size(96, 24)
        Me.BtnIn.TabIndex = 39
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(67, 71)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(81, 18)
        Me.Label5.TabIndex = 41
        Me.Label5.Text = "Dạng bào chế"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'TxtTenDangBaoChe
        '
        Me.TxtTenDangBaoChe.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtTenDangBaoChe.Location = New System.Drawing.Point(291, 67)
        Me.TxtTenDangBaoChe.MaxLength = 50
        Me.TxtTenDangBaoChe.Name = "TxtTenDangBaoChe"
        Me.TxtTenDangBaoChe.Size = New System.Drawing.Size(400, 22)
        Me.TxtTenDangBaoChe.TabIndex = 42
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToResizeColumns = False
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.BackgroundColor = System.Drawing.Color.LightBlue
        DataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.DataGridView1.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle1
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.MaduocphamDataGridViewTextBoxColumn, Me.MabaocheDataGridViewTextBoxColumn, Me.TenduocphamDataGridViewTextBoxColumn, Me.MadonggoiDataGridViewTextBoxColumn})
        Me.DataGridView1.DataSource = Me.TblmahoathanhphamBindingSource
        Me.DataGridView1.Location = New System.Drawing.Point(12, 180)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.Size = New System.Drawing.Size(768, 390)
        Me.DataGridView1.TabIndex = 48
        '
        'MaduocphamDataGridViewTextBoxColumn
        '
        Me.MaduocphamDataGridViewTextBoxColumn.DataPropertyName = "maduocpham"
        Me.MaduocphamDataGridViewTextBoxColumn.HeaderText = "Mã số"
        Me.MaduocphamDataGridViewTextBoxColumn.Name = "MaduocphamDataGridViewTextBoxColumn"
        Me.MaduocphamDataGridViewTextBoxColumn.ReadOnly = True
        Me.MaduocphamDataGridViewTextBoxColumn.Width = 150
        '
        'MabaocheDataGridViewTextBoxColumn
        '
        Me.MabaocheDataGridViewTextBoxColumn.DataPropertyName = "mabaoche"
        Me.MabaocheDataGridViewTextBoxColumn.HeaderText = "Dạng bào chế"
        Me.MabaocheDataGridViewTextBoxColumn.Name = "MabaocheDataGridViewTextBoxColumn"
        Me.MabaocheDataGridViewTextBoxColumn.ReadOnly = True
        Me.MabaocheDataGridViewTextBoxColumn.Width = 150
        '
        'TenduocphamDataGridViewTextBoxColumn
        '
        Me.TenduocphamDataGridViewTextBoxColumn.DataPropertyName = "tenduocpham"
        Me.TenduocphamDataGridViewTextBoxColumn.HeaderText = "Tên DP"
        Me.TenduocphamDataGridViewTextBoxColumn.Name = "TenduocphamDataGridViewTextBoxColumn"
        Me.TenduocphamDataGridViewTextBoxColumn.ReadOnly = True
        Me.TenduocphamDataGridViewTextBoxColumn.Width = 200
        '
        'MadonggoiDataGridViewTextBoxColumn
        '
        Me.MadonggoiDataGridViewTextBoxColumn.DataPropertyName = "madonggoi"
        Me.MadonggoiDataGridViewTextBoxColumn.HeaderText = "Mã đóng gói"
        Me.MadonggoiDataGridViewTextBoxColumn.Name = "MadonggoiDataGridViewTextBoxColumn"
        Me.MadonggoiDataGridViewTextBoxColumn.ReadOnly = True
        Me.MadonggoiDataGridViewTextBoxColumn.Width = 200
        '
        'TblmahoathanhphamBindingSource
        '
        Me.TblmahoathanhphamBindingSource.DataMember = "tbl_mahoathanhpham"
        Me.TblmahoathanhphamBindingSource.DataSource = Me.DataSetForm_Sop
        '
        'DataSetForm_Sop
        '
        Me.DataSetForm_Sop.DataSetName = "DataSetForm_Sop"
        Me.DataSetForm_Sop.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'CboDangBaoChe
        '
        Me.CboDangBaoChe.ArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboDangBaoChe.ArrowColor = System.Drawing.Color.Black
        Me.CboDangBaoChe.BindedControl = Nothing
        Me.CboDangBaoChe.BorderStyle = MTGCComboBox.TipiBordi.Fixed3D
        Me.CboDangBaoChe.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal
        Me.CboDangBaoChe.ColumnNum = 1
        Me.CboDangBaoChe.ColumnWidth = "121"
        Me.CboDangBaoChe.DisabledArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboDangBaoChe.DisabledArrowColor = System.Drawing.Color.LightGray
        Me.CboDangBaoChe.DisabledBackColor = System.Drawing.SystemColors.Control
        Me.CboDangBaoChe.DisabledBorderColor = System.Drawing.SystemColors.InactiveBorder
        Me.CboDangBaoChe.DisabledForeColor = System.Drawing.SystemColors.GrayText
        Me.CboDangBaoChe.DisplayMember = "Text"
        Me.CboDangBaoChe.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.CboDangBaoChe.DropDownBackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(238, Byte), Integer))
        Me.CboDangBaoChe.DropDownForeColor = System.Drawing.Color.Black
        Me.CboDangBaoChe.DropDownStyle = MTGCComboBox.CustomDropDownStyle.DropDown
        Me.CboDangBaoChe.DropDownWidth = 141
        Me.CboDangBaoChe.GridLineColor = System.Drawing.Color.LightGray
        Me.CboDangBaoChe.GridLineHorizontal = False
        Me.CboDangBaoChe.GridLineVertical = False
        Me.CboDangBaoChe.LoadingType = MTGCComboBox.CaricamentoCombo.ComboBoxItem
        Me.CboDangBaoChe.Location = New System.Drawing.Point(151, 67)
        Me.CboDangBaoChe.ManagingFastMouseMoving = True
        Me.CboDangBaoChe.ManagingFastMouseMovingInterval = 30
        Me.CboDangBaoChe.Name = "CboDangBaoChe"
        Me.CboDangBaoChe.SelectedItem = Nothing
        Me.CboDangBaoChe.SelectedValue = Nothing
        Me.CboDangBaoChe.Size = New System.Drawing.Size(138, 21)
        Me.CboDangBaoChe.TabIndex = 49
        '
        'CboSanPham
        '
        Me.CboSanPham.ArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboSanPham.ArrowColor = System.Drawing.Color.Black
        Me.CboSanPham.BindedControl = Nothing
        Me.CboSanPham.BorderStyle = MTGCComboBox.TipiBordi.Fixed3D
        Me.CboSanPham.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal
        Me.CboSanPham.ColumnNum = 1
        Me.CboSanPham.ColumnWidth = "121"
        Me.CboSanPham.DisabledArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboSanPham.DisabledArrowColor = System.Drawing.Color.LightGray
        Me.CboSanPham.DisabledBackColor = System.Drawing.SystemColors.Control
        Me.CboSanPham.DisabledBorderColor = System.Drawing.SystemColors.InactiveBorder
        Me.CboSanPham.DisabledForeColor = System.Drawing.SystemColors.GrayText
        Me.CboSanPham.DisplayMember = "Text"
        Me.CboSanPham.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.CboSanPham.DropDownBackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(238, Byte), Integer))
        Me.CboSanPham.DropDownForeColor = System.Drawing.Color.Black
        Me.CboSanPham.DropDownStyle = MTGCComboBox.CustomDropDownStyle.DropDown
        Me.CboSanPham.DropDownWidth = 141
        Me.CboSanPham.GridLineColor = System.Drawing.Color.LightGray
        Me.CboSanPham.GridLineHorizontal = False
        Me.CboSanPham.GridLineVertical = False
        Me.CboSanPham.LoadingType = MTGCComboBox.CaricamentoCombo.ComboBoxItem
        Me.CboSanPham.Location = New System.Drawing.Point(151, 92)
        Me.CboSanPham.ManagingFastMouseMoving = True
        Me.CboSanPham.ManagingFastMouseMovingInterval = 30
        Me.CboSanPham.Name = "CboSanPham"
        Me.CboSanPham.SelectedItem = Nothing
        Me.CboSanPham.SelectedValue = Nothing
        Me.CboSanPham.Size = New System.Drawing.Size(138, 21)
        Me.CboSanPham.TabIndex = 52
        '
        'TxtTenSanPham
        '
        Me.TxtTenSanPham.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtTenSanPham.Location = New System.Drawing.Point(291, 92)
        Me.TxtTenSanPham.MaxLength = 50
        Me.TxtTenSanPham.Name = "TxtTenSanPham"
        Me.TxtTenSanPham.Size = New System.Drawing.Size(400, 22)
        Me.TxtTenSanPham.TabIndex = 51
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(67, 95)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(81, 18)
        Me.Label6.TabIndex = 50
        Me.Label6.Text = "Tên hàng hóa"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'CboDangDongGoi
        '
        Me.CboDangDongGoi.ArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboDangDongGoi.ArrowColor = System.Drawing.Color.Black
        Me.CboDangDongGoi.BindedControl = Nothing
        Me.CboDangDongGoi.BorderStyle = MTGCComboBox.TipiBordi.Fixed3D
        Me.CboDangDongGoi.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal
        Me.CboDangDongGoi.ColumnNum = 1
        Me.CboDangDongGoi.ColumnWidth = "121"
        Me.CboDangDongGoi.DisabledArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboDangDongGoi.DisabledArrowColor = System.Drawing.Color.LightGray
        Me.CboDangDongGoi.DisabledBackColor = System.Drawing.SystemColors.Control
        Me.CboDangDongGoi.DisabledBorderColor = System.Drawing.SystemColors.InactiveBorder
        Me.CboDangDongGoi.DisabledForeColor = System.Drawing.SystemColors.GrayText
        Me.CboDangDongGoi.DisplayMember = "Text"
        Me.CboDangDongGoi.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.CboDangDongGoi.DropDownBackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(238, Byte), Integer))
        Me.CboDangDongGoi.DropDownForeColor = System.Drawing.Color.Black
        Me.CboDangDongGoi.DropDownStyle = MTGCComboBox.CustomDropDownStyle.DropDown
        Me.CboDangDongGoi.DropDownWidth = 141
        Me.CboDangDongGoi.GridLineColor = System.Drawing.Color.LightGray
        Me.CboDangDongGoi.GridLineHorizontal = False
        Me.CboDangDongGoi.GridLineVertical = False
        Me.CboDangDongGoi.LoadingType = MTGCComboBox.CaricamentoCombo.ComboBoxItem
        Me.CboDangDongGoi.Location = New System.Drawing.Point(151, 116)
        Me.CboDangDongGoi.ManagingFastMouseMoving = True
        Me.CboDangDongGoi.ManagingFastMouseMovingInterval = 30
        Me.CboDangDongGoi.Name = "CboDangDongGoi"
        Me.CboDangDongGoi.SelectedItem = Nothing
        Me.CboDangDongGoi.SelectedValue = Nothing
        Me.CboDangDongGoi.Size = New System.Drawing.Size(138, 21)
        Me.CboDangDongGoi.TabIndex = 55
        '
        'TxtDangDongGoi
        '
        Me.TxtDangDongGoi.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtDangDongGoi.Location = New System.Drawing.Point(291, 116)
        Me.TxtDangDongGoi.MaxLength = 50
        Me.TxtDangDongGoi.Name = "TxtDangDongGoi"
        Me.TxtDangDongGoi.Size = New System.Drawing.Size(400, 22)
        Me.TxtDangDongGoi.TabIndex = 54
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(67, 117)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(81, 18)
        Me.Label4.TabIndex = 53
        Me.Label4.Text = "Dạng đóng gói"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'TxtKyHieu
        '
        Me.TxtKyHieu.BackColor = System.Drawing.SystemColors.Window
        Me.TxtKyHieu.Font = New System.Drawing.Font("Arial", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtKyHieu.Location = New System.Drawing.Point(151, 40)
        Me.TxtKyHieu.MaxLength = 10
        Me.TxtKyHieu.Name = "TxtKyHieu"
        Me.TxtKyHieu.Size = New System.Drawing.Size(138, 25)
        Me.TxtKyHieu.TabIndex = 56
        Me.TxtKyHieu.Text = "S"
        Me.TxtKyHieu.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'txtCapNhatThanh
        '
        Me.txtCapNhatThanh.BackColor = System.Drawing.SystemColors.Info
        Me.txtCapNhatThanh.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtCapNhatThanh.ForeColor = System.Drawing.Color.Red
        Me.txtCapNhatThanh.Location = New System.Drawing.Point(554, 40)
        Me.txtCapNhatThanh.MaxLength = 10
        Me.txtCapNhatThanh.Name = "txtCapNhatThanh"
        Me.txtCapNhatThanh.Size = New System.Drawing.Size(138, 26)
        Me.txtCapNhatThanh.TabIndex = 57
        Me.txtCapNhatThanh.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(453, 44)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(96, 18)
        Me.Label7.TabIndex = 58
        Me.Label7.Text = "Cập nhật thành"
        '
        'frmMaHoaSanPham
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.LightBlue
        Me.ClientSize = New System.Drawing.Size(792, 573)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.txtCapNhatThanh)
        Me.Controls.Add(Me.TxtKyHieu)
        Me.Controls.Add(Me.CboDangDongGoi)
        Me.Controls.Add(Me.TxtDangDongGoi)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.CboSanPham)
        Me.Controls.Add(Me.TxtTenSanPham)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.CboDangBaoChe)
        Me.Controls.Add(Me.DataGridView1)
        Me.Controls.Add(Me.TxtTenDangBaoChe)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.BtnIn)
        Me.Controls.Add(Me.BtnClose)
        Me.Controls.Add(Me.txtMaHangHoa)
        Me.Controls.Add(Me.btnDelete1)
        Me.Controls.Add(Me.btnNew)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmMaHoaSanPham"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Ma Hoa Danh Muc San Pham"
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TblmahoathanhphamBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetForm_Sop, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private data1, data2, data3 As DataTable
    Private da As MySqlDataAdapter
    Dim sqlQuery As String = ""
    Dim data As DataTable
    Dim myDT As New DataTable
    Dim strError As String = ""
    Dim myform As Form

    Dim stateTaoMoi As Boolean = False
    Dim stateCapNhatThanh As Boolean = False

    Private Sub loadMa(ByVal ma As String)
        Dim DangBaoChe As String = ma.Substring(1, 2)
        Dim TenSanPham As String = ma.Substring(3, 3)
        Dim DangDongGoi As String = ma.Substring(6)
        For i As Integer = 0 To Me.data1.Rows.Count - 1
            If DangBaoChe = Me.data1.Rows.Item(i).Item(0) Then
                Me.CboDangBaoChe.SelectedIndex = i
                Exit For
            End If
        Next
        For j As Integer = 0 To Me.data1.Rows.Count - 1
            If DangDongGoi = Me.data2.Rows.Item(j).Item(0) Then
                Me.CboDangDongGoi.SelectedIndex = j
                Exit For
            End If
        Next
        For k As Integer = 0 To Me.data3.Rows.Count - 1
            If TenSanPham = Me.data3.Rows.Item(k).Item(0) Then
                Me.CboSanPham.SelectedIndex = k
                Exit For
            End If
        Next
    End Sub

    Sub SetclearData()
        txtMaHangHoa.Text = ""
        CboDangDongGoi.Text = ""
        CboDangBaoChe.Text = ""
        CboSanPham.Text = ""
        TxtTenDangBaoChe.Text = ""
        TxtDangDongGoi.Text = ""
        TxtTenSanPham.Text = ""

    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        ' Kiểm tra có nhập liệu chưa ?
        ' If Me.checkInput(txtMa_QUAN.Text, txtTen_QUAN.Text) Then
        Dim txtMaQuan = Me.txtMaHangHoa.Text.Trim
        sqlQuery = "SELECT maduocpham FROM tbl_mahoathanhpham WHERE maduocpham= '" & txtMaQuan & "'"
        Dim existedMamon As Integer = moduleDatabaseConn.CheckRecordExisted(sqlQuery)
        If existedMamon = 0 And checkInput() = True Then ' Update record
            sqlQuery = "INSERT INTO tbl_mahoathanhpham "
            sqlQuery += "(maduocpham, mabaoche,tenduocpham,madonggoi) "
            sqlQuery += "VALUES "
            sqlQuery += "("
            sqlQuery += "'" & txtMaHangHoa.Text.ToUpper & "', "
            sqlQuery += "'" & Me.CboDangBaoChe.SelectedItem.Col2 & "', "
            sqlQuery += "'" & Me.CboSanPham.SelectedItem.Col2 & "',"
            sqlQuery += "'" & Me.CboDangDongGoi.SelectedItem.Col2 & "' "
            sqlQuery += ")"
            Dim insert As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
            If insert = 1 Then
                MessageBox.Show("Thêm thành công thành công !")
                sqlQuery = "SELECT * FROM tbl_mahoathanhpham"
                Me.loadDanhSachDanhmucSanPham(sqlQuery)
                Me.stateTaoMoi = False
            Else
                MessageBox.Show("Thêm thông tin không thành công: " & globalVariale.sqlMsgError)
            End If

        Else
            If existedMamon = 1 Then
                moduleConstants.MessageWarning = "Mã  " & txtMaHangHoa.Text & " đã có , bạn muốn cập nhật không ?"
                If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                    ' Update record
                    If checkInput() = True Then
                        sqlQuery = "INSERT INTO tbl_mahoathanhpham "
                        sqlQuery += "(maduocpham, mabaoche,tenduocpham,madonggoi) "
                        sqlQuery += "VALUES "
                        sqlQuery += "("
                        sqlQuery += "'" & txtCapNhatThanh.Text.ToUpper & "', "
                        sqlQuery += "'" & Me.CboDangBaoChe.SelectedItem.Col2 & "', "
                        sqlQuery += "'" & Me.CboSanPham.SelectedItem.Col2 & "',"
                        sqlQuery += "'" & Me.CboDangDongGoi.SelectedItem.Col2 & "' "
                        sqlQuery += ")"
                        Dim insert As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                        Dim sqlQueryDelete As String = "DELETE FROM tbl_mahoathanhpham WHERE maduocpham = '" & txtMaHangHoa.Text & "'"
                        Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQueryDelete)
                        If deleting = 1 Then
                            MessageBox.Show("Cập nhật thông tin thành công !")
                            sqlQuery = "SELECT * FROM tbl_mahoathanhpham"
                            Me.loadDanhSachDanhmucSanPham(sqlQuery)
                            Me.stateCapNhatThanh = False
                        Else
                            MessageBox.Show("Cập nhật thông tin không thành công: " & globalVariale.sqlMsgError)
                        End If
                    Else ' SQLExeption: existedMaQuocGia = -1
                        MessageBox.Show("Lấy dữ liệu bị lỗi: " & globalVariale.sqlMsgError, "Lấy dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        SetclearData()
        txtMaHangHoa.Focus()
        Me.stateTaoMoi = True
        Me.stateCapNhatThanh = False
        '******************
        Me.txtCapNhatThanh.Text = ""
        Me.txtMaHangHoa.Text = ""

    End Sub
    Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete1.Click
        Dim txtMaQuan As String = Trim(Me.txtMaHangHoa.Text)
        If txtMaQuan = "" Then
            MessageBox.Show("Bạn chưa chọn Mã để xóa !")
        Else
            Dim txtTenQuan As String = Trim(Me.TxtTenSanPham.Text)
            moduleConstants.MessageWarning = "Bạn có muốn xóa " & txtMaQuan & "(" & txtTenQuan & ") ?"
            If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                Dim sqlQuery As String = "DELETE FROM tbl_mahoathanhpham WHERE maduocpham = '" & txtMaQuan & "'"
                Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If deleting = 1 Then
                    MessageBox.Show("Xóa thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_mahoathanhpham"
                    Me.loadDanhSachDanhmucSanPham(sqlQuery)
                    SetclearData()
                Else
                    MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
                End If
            End If
            '************************************
            Me.stateCapNhatThanh = False
            Me.stateTaoMoi = False
        End If
    End Sub

    Private Sub frmMaHoaSanPham_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Me.loadDanhSachDangBaoche()
        Me.loadDanhSachDangDongGoi()
        Me.loadDanhSachTenSanPham()
        SetclearData()
        '***************
        Me.stateCapNhatThanh = False
        Me.stateTaoMoi = True

    End Sub

    Private Sub FrmMaHoaSanPham_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        moduleUtils.setDinhDangVietNam()
        Me.loadDanhSachDanhmucSanPham("SELECT maduocpham,mabaoche,tenduocpham,madonggoi FROM tbl_mahoathanhpham")

    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub

    Function checkInput() As Boolean
        sqlQuery = "SELECT maduocpham FROM tbl_mahoathanhpham WHERE maduocpham = '" & txtMaHangHoa.Text & "'"
        Dim existedMamon As Integer = moduleDatabaseConn.CheckRecordExisted(sqlQuery)
        Dim result As Boolean = True
        If Me.txtCapNhatThanh.Text = Me.txtMaHangHoa.Text Then
            MessageBox.Show("Không được cập nhật mã trùng hoặc rỗng !!!")
            result = False
        ElseIf Me.txtCapNhatThanh.Text = "" And Me.txtMaHangHoa.Text = "" Then
            MessageBox.Show("Không được cập nhật mã trùng hoặc rỗng !!!")
            result = False
        ElseIf existedMamon = 1 And Me.txtCapNhatThanh.Text = "" Then
            MessageBox.Show(" Không thể cập nhật mã rỗng !")
            result = False
        End If
        Return result
    End Function

    Private Sub loadDanhSachDanhmucSanPham(ByVal sqlQuery As String)
        Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
    End Sub
    Private Sub loadDanhSachDangBaoche()
        Dim sqlQuery As String = ""
        sqlQuery = "SELECT ma, ten FROM tbl_dangbaoche ORDER BY ma"
        data1 = moduleDatabaseConn.GetDataTable(sqlQuery)
        CboDangBaoChe.Items.Clear()
        CboDangBaoChe.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
        CboDangBaoChe.ColumnNum = 2
        CboDangBaoChe.ColumnWidth = "100;250"
        CboDangBaoChe.HighlightBorderColor = Color.Black
        CboDangBaoChe.GridLineHorizontal = True
        CboDangBaoChe.GridLineVertical = True
        CboDangBaoChe.ItemHeight = 17
        CboDangBaoChe.DropDownHeight = 300
        CboDangBaoChe.SourceDataTable = data1
        CboDangBaoChe.SelectedIndex = 0
    End Sub
    Private Sub CboDangBaoChe_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboDangBaoChe.SelectedIndexChanged
        Me.TxtTenDangBaoChe.Text = Me.CboDangBaoChe.SelectedItem.Col2
        If Me.stateCapNhatThanh = True Then
            loadKeyCapNhat()
        Else
            loadKey()
        End If
    End Sub
    Private Sub loadDanhSachDangDongGoi()
        Dim sqlQuery As String = ""
        sqlQuery = "SELECT ma, ten FROM tbl_dangdonggoi ORDER BY ma"
        data2 = moduleDatabaseConn.GetDataTable(sqlQuery)
        CboDangDongGoi.Items.Clear()
        CboDangDongGoi.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
        CboDangDongGoi.ColumnNum = 2
        CboDangDongGoi.ColumnWidth = "100;250"
        CboDangDongGoi.HighlightBorderColor = Color.Black
        CboDangDongGoi.GridLineHorizontal = True
        CboDangDongGoi.GridLineVertical = True
        CboDangDongGoi.ItemHeight = 17
        CboDangDongGoi.DropDownHeight = 300
        CboDangDongGoi.SourceDataTable = data2
        CboDangDongGoi.SelectedIndex = 0
    End Sub
    Private Sub CboDangDongGoi_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboDangDongGoi.SelectedIndexChanged
        Me.TxtDangDongGoi.Text = Me.CboDangDongGoi.SelectedItem.Col2
        If Me.stateCapNhatThanh = True Then
            loadKeyCapNhat()
        Else
            loadKey()
        End If
    End Sub
    Private Sub loadDanhSachTenSanPham()
        Dim sqlQuery As String = ""
        sqlQuery = "SELECT ma, ten FROM tbl_danhmuc_duocpham ORDER BY ma"
        data3 = moduleDatabaseConn.GetDataTable(sqlQuery)
        CboSanPham.Items.Clear()
        CboSanPham.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
        CboSanPham.ColumnNum = 2
        CboSanPham.ColumnWidth = "100;250"
        CboSanPham.HighlightBorderColor = Color.Black
        CboSanPham.GridLineHorizontal = True
        CboSanPham.GridLineVertical = True
        CboSanPham.ItemHeight = 17
        CboSanPham.DropDownHeight = 300
        CboSanPham.SourceDataTable = data3
        CboSanPham.SelectedIndex = 0
    End Sub
    Private Sub CboSanPham_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboSanPham.SelectedIndexChanged
        Me.TxtTenSanPham.Text = Me.CboSanPham.SelectedItem.Col2
        If Me.stateCapNhatThanh = True Then
            loadKeyCapNhat()
        Else
            loadKey()
        End If
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Me.stateCapNhatThanh = True
        Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
        Me.txtMaHangHoa.Text = Me.DataGridView1.Item(0, iRow).Value
        loadMa(Me.DataGridView1.Item(0, iRow).Value)

    End Sub

    Private Sub BtnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnIn.Click
        FrmCrMahoaHangHoa.Show()
    End Sub

    Private Sub loadKey()
        Dim key As String = Me.TxtKyHieu.Text.ToUpper + Me.CboDangBaoChe.Text.ToUpper + Me.CboSanPham.Text.ToUpper + Me.CboDangDongGoi.Text.ToUpper

        If Me.stateTaoMoi = True Then
            Me.txtMaHangHoa.Text = key
        Else
            Me.txtMaHangHoa.Text = ""
        End If


        Me.txtCapNhatThanh.ReadOnly = True
        Me.txtMaHangHoa.ReadOnly = True
    End Sub

    Private Sub loadKeyCapNhat()
        Dim key As String = Me.TxtKyHieu.Text.ToUpper + Me.CboDangBaoChe.Text.ToUpper + Me.CboSanPham.Text.ToUpper + Me.CboDangDongGoi.Text.ToUpper
        If Me.stateCapNhatThanh = True Then
            Me.txtCapNhatThanh.Text = key
        Else
            Me.txtCapNhatThanh.Text = ""
        End If
        Me.txtCapNhatThanh.ReadOnly = True
        Me.txtMaHangHoa.ReadOnly = True
    End Sub
    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Me.stateCapNhatThanh = True
    End Sub
End Class


